package com.cloud.streamrabbitmqproducer.sender.impl;

import com.cloud.streamrabbitmqproducer.sender.MessageSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.Random;

/**
 * @author kangwen
 */
@Slf4j
@EnableBinding(Source.class)
public class RabbitMqMessageSender implements MessageSender {

	@Resource
	@Qualifier("output")
	private MessageChannel messageChannel;

	@Override
	public void send() {
		String msg = Thread.currentThread().getName() + "==" + new Random().nextInt();
		log.info("producer a message: {}", msg);
		messageChannel.send(MessageBuilder.withPayload(msg).build());
	}
}
